package com.sto.stoapp.activity.scanner;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.activity.scanner.inquiry.FastInquiryActivity;
import com.sto.stoapp.activity.scanner.inquiry.InquirySelectActivity;
import com.sto.stoapp.activity.scanner.inquiry.PictureInquiryActivity;
import com.sto.stoapp.activity.scanner.inquiry.TimeInquiryActivity;
import com.sto.stoapp.adapter.InquiryMenuAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.dataprocess.ProcessTableData;
import com.sto.stoapp.entity.InquiryEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.log.ExceptionLog;
import com.sto.stoapp.util.UnifiedStaticType;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 记录查询
 * 
 * @author Administrator
 * 
 */
public class StoRecordscheckActivity extends StoHomeActivity {
	private ListView datalist = null; // 定义ListView组件
	private List<InquiryEntity> list = new ArrayList<InquiryEntity>(); // 定义显示的内容包装
	private InquiryEntity inquiryEntity;
	private ProcessTableData tableData;
	private String action;
    private String picType;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.sto_inquirymenu_list);
		Bundle extras = getIntent().getExtras();
		action = extras.getString("busiType");
		picType=extras.getString("bus");
		this.setTitleBottom(R.string.record_search, action);
		ExceptionLog.writeLog("StoRecordscheckActivity Broad", action);
		tableData = new ProcessTableData();
		initWidget();
	}

	private void initWidget() {
		this.datalist = (ListView) super.findViewById(R.id.dest_list); // 取得组件
		datalist.setOnItemClickListener(new StoOnItemClickListener(this) {
			@Override
			public void KcOnItemClickListener(AdapterView<?> parent, View view,
					int position, long id) {
				String itemText = list.get(position).getMenuName();
				// 快速搜索单号
				if (itemText.equals(getString(R.string.fast_search_code))) {
					Intent intent = new Intent(StoRecordscheckActivity.this,
							FastInquiryActivity.class);
					// 返回广播事件
					intent.putExtra(HomeBroadAction.BROAD_TYPE, action);
					startActivity(intent);
//					Helper.showToast(StoRecordscheckActivity.this, "功能暂未开启");
					return;
				}
				//时间段查询
				if (itemText.equals(getString(R.string.time_inquiry))) {
					Intent intent = new Intent(StoRecordscheckActivity.this,
							TimeInquiryActivity.class);
					// 返回广播事件
					intent.putExtra(HomeBroadAction.BROAD_TYPE, action);
					intent.putExtra("inquiry_type", UnifiedStaticType.loginType);
					startActivity(intent);
//					Helper.showToast(StoRecordscheckActivity.this, "功能暂未开启");
					return;
				}
				// 查询拍照图片
				if (itemText.equals(getString(R.string.picture_inquiry))) {
					Intent intent = new Intent(StoRecordscheckActivity.this,
							PictureInquiryActivity.class);
					// 返回广播事件
					intent.putExtra("bus", picType);
					intent.putExtra(HomeBroadAction.BROAD_TYPE, action);
					startActivity(intent);
				} else {

					Intent intent = new Intent(StoRecordscheckActivity.this,
							InquirySelectActivity.class);
					// 查询数据项名称
					intent.putExtra("inquiryNameItem",
							tableData.getProcessInquiryData(position, 0));
					// 查询对应表名的序号
					intent.putExtra("inquiryTableItem",
							tableData.getProcessInquiryData(position, 1));
					intent.putExtra("inquiryItemText", itemText);
					startActivity(intent);
				}
			}
		});

		displayListView();
	}

	private void displayListView() {
		int maxItem = tableData.getInquiryMaxItem();
		ExceptionLog.writeLog("StoRecordscheckActivity", "maxItem:" + maxItem);
		for (int x = 0; x < maxItem; x++) {
			inquiryEntity = new InquiryEntity();
			inquiryEntity.setMenuName(getString(tableData
					.getProcessInquiryData(x, 0)));
			inquiryEntity.setImageId(R.drawable.next);
			this.list.add(inquiryEntity); // 保存了所有的数据行
		}
		InquiryMenuAdapter menuAdapter = new InquiryMenuAdapter(this, list);
		datalist.setAdapter(menuAdapter);
	}

}
